
def isHappy(n: int) -> bool:
    repeat = set()
    from collections import deque
    queue = deque([n])
    while queue:
        q = queue.popleft()
        if q in repeat:
            return False
        repeat.add(q)
        result = 0
        while q:
            result += (q%10)**2
            q //= 10
        queue.append(result)
    return True

print(isHappy(19))